package com.bs.modules.use.service.impl;

import com.bs.common.utils.DateUtils;
import com.bs.modules.use.entity.AppPowerEntity;
import com.bs.modules.use.entity.AppPriceEntity;
import com.bs.modules.use.entity.AppUserEntity;
import com.bs.modules.use.service.AppPriceService;
import com.bs.modules.use.service.AppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bs.common.utils.PageUtils;
import com.bs.common.utils.Query;

import com.bs.modules.use.dao.AppWaterDao;
import com.bs.modules.use.entity.AppWaterEntity;
import com.bs.modules.use.service.AppWaterService;


@Service("appWaterService")
public class AppWaterServiceImpl extends ServiceImpl<AppWaterDao, AppWaterEntity> implements AppWaterService {

    @Autowired
    private AppWaterDao appWaterDao;

    @Autowired
    private AppPriceService appPriceService;

    @Autowired
    private AppUserService appUserService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AppWaterEntity> page = this.page(
                new Query<AppWaterEntity>().getPage(params),
                new QueryWrapper<AppWaterEntity>()
        );


        for (AppWaterEntity waterEntity : page.getRecords()) {
            AppPriceEntity appPriceEntity = appPriceService.getById(waterEntity.getWaterPriceid());
            waterEntity.setPowerWaterName(appPriceEntity.getPowerprice());

            AppUserEntity appUserEntity = appUserService.getById(waterEntity.getUserId());
            waterEntity.setUserName(appUserEntity.getUserUsername());

            waterEntity.setWaterStatusCn("1".equals(waterEntity.getWaterStatus()) ? "待缴费" : "已缴费");

        }


        return new PageUtils(page);
    }

    @Override
    public List<AppWaterEntity> findOrder(Object openid, Object status) {
        List<AppWaterEntity> list = appWaterDao.findInfoByStatus(String.valueOf(openid), String.valueOf(status));
        return list;
    }

    @Override
    public void pay(Object orderId, Object payMoney) {
        String payTime = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        appWaterDao.pay(String.valueOf(orderId), String.valueOf(payMoney), payTime, "2");
    }

}
